package com.springhone.side.web;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.springhone.side.utils.ConfigManager;

@Controller
@RequestMapping("/home")
public class HomeController {

    private static final Log logger = LogFactory.getLog(HomeController.class);

    private static final Log homeLogger = LogFactory.getLog("homeLogger");

    @RequestMapping(value = "/catalog", method = RequestMethod.GET)
    public String getTutorial(ModelMap model) {
        model.addAttribute("catalogs", getCatalogName());
        return "home/index";
    }

    public List<String> getCatalogName() {
        List<String> reuslt = new ArrayList<String>();
        String catalogNames = ConfigManager.getInstance().getProperty("catalogs");
        if(homeLogger.isDebugEnabled()) {
            homeLogger.debug("catalogNames:" + catalogNames);
        }
        if (catalogNames != null && catalogNames.length() > 0) {
            for (String tmp : catalogNames.split(",")) {
                reuslt.add(tmp);
            }
        } else {
            logger.error("there is not any messages");
        }
        return reuslt;
    }
}
